﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using PluginInterface;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace IotModel
{
    public class DeviceVariableModel
    {
        /// <summary>
        /// 变量名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 方法
        /// </summary>
        public string Method { get; set; }
        /// <summary>
        /// 地址
        /// </summary>
        public string DeviceAddress { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        public DataTypeEnum DataType { get; set; }
        /// <summary>
        /// 大小端
        /// </summary>
        public EndianEnum EndianType { get; set; }
        /// <summary>
        /// 表达式
        /// </summary>
        public string Expressions { get; set; }
        /// <summary>
        /// 上传
        /// </summary>
        public bool IsUpload { get; set; }
        /// <summary>
        /// 权限
        /// </summary>
        public ProtectTypeEnum ProtectType { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public uint Index { get; set; }

        [Newtonsoft.Json.JsonIgnore]
        public DeviceModel Device { get; set; }
        /// <summary>
        /// 设备
        /// </summary>
        public Guid? DeviceId { get; set; }
        /// <summary>
        /// 别名
        /// </summary>
        public string Alias { get; set; }

        [NotMapped]
        //原值
        public object Value { get; set; }
        [NotMapped]
        //值
        public object CookedValue { get; set; }
        [NotMapped]
        public string Message { get; set; }
        [NotMapped]
        ///更新时间
        public DateTime Timestamp { get; set; }
        [NotMapped]
        //状态
        [JsonConverter(typeof(StringEnumConverter))]
        public VaribaleStatusTypeEnum StatusType { get; set; } = VaribaleStatusTypeEnum.UnKnow;
    }
}